package com.cheng.common.utils;

import java.io.Serializable;

public class BaseResult<T> implements Serializable {

    private boolean success;

    private T content;

    private String code;

    private String message;


    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static <T> BaseResult successResult(T content) {
        BaseResult result = new BaseResult();
        result.success(content);
        return result;
    }

    public static <T> BaseResult failureResult(Exception e) {
        BaseResult result = new BaseResult();
        result.failure(e);
        return result;
    }

    public static <T> BaseResult failureResult(String message) {
        BaseResult result = new BaseResult();
        result.failure(message);
        return result;
    }

    public BaseResult success(T content) {
        this.success = true;
        this.content = content;
        return this;
    }

    public BaseResult failure(Exception e) {
        this.success = false;
        this.message = e.getMessage();
        return this;
    }

    public BaseResult failure(String msg) {
        this.success = false;
        this.message = msg;
        return this;
    }
}
